package com.henu.xyh;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.henu.R;
import com.henu.yizhiya.entity.Person;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.UpdateListener;

public class TelActivity extends AppCompatActivity {

    private ImageButton tel_return;
    private Button tel_save;
    private EditText tel_edit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tel);
        tel_return= (ImageButton) findViewById(R.id.tel_return);
        tel_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                finish();
            }
        });
        tel_save= (Button) findViewById(R.id.tel_save);
        tel_edit= (EditText) findViewById(R.id.tel_edit);
        final Person person= BmobUser.getCurrentUser(Person.class);
        tel_edit.setText(person.getMobilePhoneNumber());
        tel_save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str=person.getMobilePhoneNumber().toString().trim();
                person.setMobilePhoneNumber(str);
                person.update(person.getMobilePhoneNumber(), new UpdateListener() {
                    @Override
                    public void done(BmobException e) {
                        if (e==null){
                            Toast.makeText(TelActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                        }
                        else {
                            Toast.makeText(TelActivity.this, "修改失败", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                finish();
            }
        });
    }
}
